package com.lagou.edu.service.impl;

import com.lagou.edu.anno.Autowired;
import com.lagou.edu.anno.Service;
import com.lagou.edu.anno.Transcational;
import com.lagou.edu.dao.AccountDao;
import com.lagou.edu.pojo.Account;
@Transcational
@Service
public class TransferServiceNoInterface {
    @Autowired
    private AccountDao accountDao;


    public void transfer(String fromCardNo, String toCardNo, int money) throws Exception {

        /*try{
            // 开启事务(关闭事务的自动提交)
            TransactionManager.getInstance().beginTransaction();*/

        Account from = accountDao.queryAccountByCardNo(fromCardNo);
        Account to = accountDao.queryAccountByCardNo(toCardNo);

        from.setMoney(from.getMoney() - money);
        to.setMoney(to.getMoney() + money);

        accountDao.updateAccountByCardNo(to);
            int c = 1/0;
        accountDao.updateAccountByCardNo(from);

    }
}
